Isopsephy test cases

See Isopsephy project from GitHub for more information about the library itself.

Load ipynbtester script


In [1]:
%load_ext ipynbtester


The ipynbtester module is not an IPython extension.

Import functions for tests


In [2]:
from isopsephy import isopsephy, to_roman, to_greek, preprocess_roman, preprocess_greek, IsopsephyException, \
                      find_cumulative_indices, find, char_table, digital_root, digital_sum, digital_product

Define tests


In [3]:
# all supported greek letters
greek_letters = "α,Α,β,Β,γ,Γ,δ,Δ,ε,Ε,ϛ,Ϛ,Ϝ,ϝ,ζ,Ζ,η,Η,θ,Θ,ι,Ι,υ,ϒ,κ,Κ,ϡ,Ϡ,Ͳ,ͳ,λ,Λ,ω,Ω,μ,Μ,τ,Τ,ν,Ν,ξ,Ξ,ο,Ο,σ,Σ,Ϲ,ϲ,ς,π,Π,χ,Χ,ϙ,Ϙ,Ϟ,ϟ,ρ,Ρ,ψ,Ψ,φ,Φ".split(',')
# all supported roman letters
roman_letters = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUwWxXyYzZ".split(',')
# john 1:1
verse = "Eν αρχη ην ο Λογος και ο Λογος ην προς τον Θεον και Θεος ην ο Λογος"

def set_up():
    pass

def test_every_supported_greek_letter_isopsephy_is_int():
    set_up()
    for letter in greek_letters:
        assert type(isopsephy(letter)) == int

def test_total_isopsephy_of_all_supported_greek_letters():
    set_up()
    #assert isopsephy(''.join(greek_letters)) == 13282
    assert isopsephy(''.join(greek_letters)) == 12582

def test_total_isopsephy_of_all_supported_roman_letters():
    set_up()
    assert isopsephy(''.join(roman_letters)) == 8374

def test_every_supported_roman_letter_isopsephy_is_int():
    set_up()
    for letter in roman_letters:
        assert type(isopsephy(letter)) == int
        
def test_unsupported_roman_letters_isopsephy():
    set_up()
    for letter in ['v']:
        try:
            isopsephy(letter)
            assert False
        except IsopsephyException:
            assert True

def test_unsupported_letters_isopsephy():
    set_up()
    for letter in ['0', '9', 'ö', 'я']:
        try:
            isopsephy(letter)
            assert False
        except IsopsephyException:
            assert True

def test_space_isopsephy():
    set_up()
    assert isopsephy(' ') == 0

accents = "ώ,ύ,ό,ϋ,ϊ,ἁ,ά,έ,ή,ί,ΰ,Έ,Ή,Ί,Ό,Ύ,Ώ,Ά,ΐ,Ὑ,Ὓ,Ὕ,Ὗ,ὑ,ὐ,ὓ,ὒ,ὕ,ὔ,ὗ,ὖ,Ὁ,Ὀ,Ὃ,Ὂ,Ὅ,Ὄ,ὁ,ὀ,ὃ,ὂ,ὅ,ὄ,ὸ,ὺ,ὼ,ὰ,ὲ,ὴ,ὶ,Ὡ,Ὠ,Ὣ,Ὢ,Ὥ,Ὤ,Ὧ,Ὦ,ὡ,ὠ,ὣ,ὢ,ὥ,ὤ,ὧ,ὦ,Ἔ,Ἕ,Ἒ,Ἓ,Ἐ,Ἑ,ἔ,ἕ,ἒ,ἓ,ἐ,ἑ,Ἆ,Ἇ,Ἄ,Ἅ,Ἂ,Ἃ,Ἀ,Ἁ,ἆ,ἇ,ἄ,ἅ,ἂ,ἃ,ἀ,ῲ,Ἶ,Ἷ,Ἴ,Ἵ,Ἲ,Ἳ,Ἰ,Ἱ,ἶ,ἷ,ἴ,ἵ,ἲ,ἳ,ἰ,ἱ,Ἦ,Ἧ,Ἤ,Ἥ,Ἢ,Ἣ,Ἠ,Ἡ,ἦ,ἧ,ἤ,ἥ,ἢ,ἣ,ἠ,ἡ,ῗ,ῖ,ῒ,Ὶ,ῇ,ῆ,ῄ,ῃ,ῂ,ῌ,Ὴ,Ὲ,ῷ,ῶ,ῴ,ῳ,î,ì,ῼ,Ὼ,Ὸ,ῧ,ῦ,ù,ῤ,ῢ,ῡ,ῠ,ó,ò,Ῥ,Ὺ,Ῡ,ô,ᾔ,ᾕ,ᾖ,ᾗ,ᾐ,ᾑ,ᾒ,ᾓ,ᾜ,ᾝ,ᾞ,ᾟ,ᾘ,ᾙ,ᾚ,ᾛ,ᾄ,ᾅ,ᾆ,ᾇ,ᾀ,ᾁ,ᾂ,ᾃ,ᾌ,ᾍ,ᾎ,ᾏ,ᾈ,ᾉ,ᾊ,ᾋ,ᾴ,ᾶ,ᾷ,ᾲ,ᾳ,ᾼ,Ὰ,ᾤ,ᾥ,ᾦ,ᾧ,ᾠ,ᾡ,ᾢ,ᾣ,ᾬ,ᾭ,ᾮ,ᾯ,ᾨ,ᾩ,ᾪ,ᾫ,ῥ"

def test_all_accents():
    set_up()
    x = preprocess_greek(''.join(accents.split(',')))
    #assert isopsephy(x) == 45958
    assert isopsephy(x) == 46688
    
def test_word_isopsephy():
    set_up()
    # isopsephia
    assert isopsephy("ισοψηφια") == 1499
    
def test_phrase_isopsephy():
    set_up()
    # john 1:1
    assert isopsephy(verse) == 3617

def test_phrase_isopsephy_via_read_file():
    set_up()
    filename = "./john1_1.txt"
    with open (filename, "r") as resource:
        data = resource.read().replace('\n', '')
        assert isopsephy(data) == 3617

def test_seven_vowels_isopsephy():
    set_up()
    assert isopsephy("αεηιουω") == 1294

def test_three_numerals_isopsephy():
    set_up()
    assert isopsephy("ϛϙϡ") == 996
    
def test_seventeen_consonants_isopsephy():
    set_up()
    assert isopsephy("βγδζθκλμνξπρστφχψ") == 2705
    
def test_twentyfour_non_numerals_isopsephy():
    set_up()
    assert isopsephy("αεηιουωβγδζθκλμνξπρστφχψ") == 3999
    
def test_greek_to_roman():
    set_up()
    assert to_roman(''.join(greek_letters)) == "aAbBgGdDeEwWWwzZêÊhHiIuUkKjJJjlLôÔmMtTnNcCoOsSSsspPxXqQQqrRyYfF"
    
def test_preprocess_roman():
    set_up()
    assert preprocess_roman("abcdefghijklmnopqrstuvwxyz0123456789") == "abcdefghijklmnopqrstuwxyz"

def test_preprocess_greek():
    set_up()
    assert preprocess_greek("öΖώ9") == "Ζω"

def test_small_roman_letters_to_greek():
    set_up()
    assert to_greek("abcdeêfghiklmnoôpqrstuwxyz") == "αβξδεηφγθικλμνοωπϙρστυϝχψζ"

def test_capital_roman_letters_to_greek():
    set_up()
    assert to_greek("ABCDEÊFGHIJKLMNOÔPQRSTUWXYZ") == "ΑΒΞΔΕΗΦΓΘΙϠΚΛΜΝΟΩΠϘΡΣΤΥϜΧΨΖ"

def test_unsupported_roman_letters_to_greek():
    set_up()
    assert to_greek("abc123") == "αβξ123"

def test_find():
    set_up()
    assert find(verse, 373) == ['Λογος', 'Λογος', 'Λογος']
    
def test_find_cumulative():
    set_up()
    assert find(verse, 443, cumulative=True) == ['ο Λογος', 'ο Λογος', 'και Θεος ην ο', 'ο Λογος']
    
def test_find_indices():
    set_up()
    assert find_cumulative_indices(map(isopsephy, verse.split()), 443) == [[3,4],[6,7],[12,13,14,15],[15,16]]
    
def test_digital_root():
    set_up()
    assert digital_root(123456789) == 9

def test_digital_sum():
    set_up()
    assert digital_sum(123456789) == 45
    
def test_digital_product():
    set_up()
    assert digital_product(123456789) == 362880
    
def test_char_table():
    set_up()
    assert str(char_table('ο Λογος')) == '<table class="char-table"><caption>ο Λογος</caption><thead><tr><th>ο</th><th>&nbsp;</th><th>&nbsp;</th><th>Λ</th><th>ο</th><th>γ</th><th>ο</th><th>ς</th></tr></thead><tfoot><tr><td colspan="1">70 <sub>7</sub></td><td/><td/><td colspan="5">373 <sub>4</sub></td></tr><tr><td colspan="9" style="border-top: solid 1px #ddd">443 <sub>11 / 2</sub></td></tr></tfoot><tbody><tr><td>o</td><td/><td class="empty-cell"/><td>L</td><td>o</td><td>g</td><td>o</td><td>s</td></tr><tr><td>70</td><td/><td class="empty-cell"/><td>30</td><td>70</td><td>3</td><td>70</td><td>200</td></tr></tbody></table>'

Run tests


In [4]:
%runaway


Out[4]:
Collected 28 tests.
Test function nameStatus
Successful28
Failed0
Errors0
Execution0.005226 seconds
test_all_accentssuccessful
test_every_supported_greek_letter_isopsephy_is_intsuccessful
test_twentyfour_non_numerals_isopsephysuccessful
test_seven_vowels_isopsephysuccessful
test_three_numerals_isopsephysuccessful
test_digital_productsuccessful
test_small_roman_letters_to_greeksuccessful
test_total_isopsephy_of_all_supported_greek_letterssuccessful
test_find_indicessuccessful
test_unsupported_letters_isopsephysuccessful
test_preprocess_greeksuccessful
test_preprocess_romansuccessful
test_greek_to_romansuccessful
test_phrase_isopsephy_via_read_filesuccessful
test_phrase_isopsephysuccessful
test_space_isopsephysuccessful
test_char_tablesuccessful
test_unsupported_roman_letters_to_greeksuccessful
test_findsuccessful
test_digital_sumsuccessful
test_word_isopsephysuccessful
test_seventeen_consonants_isopsephysuccessful
test_digital_rootsuccessful
test_capital_roman_letters_to_greeksuccessful
test_every_supported_roman_letter_isopsephy_is_intsuccessful
test_unsupported_roman_letters_isopsephysuccessful
test_find_cumulativesuccessful
test_total_isopsephy_of_all_supported_roman_letterssuccessful

Styles for tests table


In [5]:
from IPython.core.display import HTML
with open('isopsephy.css') as f:
    css = f.read()
HTML('<style>%s</style>' % css)


Out[5]:

The MIT License

Copyright (c) 2015 Marko Manninen